﻿/// Copyright © 2013 Microsoft Corporation. 
/// This project is released under the Microsoft Public License (MS-PL)
///
namespace DataMorph.Processing
{
    using System;

    using DataMorph.Common.Contracts;

    public class TagParser : ITagParser
    {
        public Tag Parse(TagData tagData)
        {
            if (tagData == null)
            {
                throw new ArgumentNullException("tagData", "Tag data must not be null.");
            }

            var tag = new Tag { Id = tagData.TagId };
            switch (tagData.Value.Length)
            {
                case 1:
                    tag.Type = TagType.Bit;
                    break;

                case 3:
                    tag.Type = TagType.Integer;
                    break;
                
                case 20:
                    tag.Type = TagType.Text;
                    break;

                default:
                    throw new ArgumentException("Unknown tag type");
            }

            return tag;
        }
    }
}